package com.alibaba.citrus.ots.platform.enhance.functions.diff.common.dataParser;

import com.alibaba.citrus.ots.platform.enhance.functions.diff.activity.constant.ActivityDiffStandardFieldDict;
import com.alibaba.citrus.ots.platform.enhance.functions.diff.common.constant.SalesOrderDiffStandardFieldDict;
import com.alibaba.citrus.ots.platform.enhance.repository.model.diff.common.FieldLineDTO;
import com.alibaba.citrus.ots.platform.enhance.repository.model.diff.common.SalesOrderDTO;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: qiaojiange
 * @create: 2022/01/23
 * @Description 销售主单解析器
 */
@Component
public class SalesOrderDataParse extends DataParser {

    /**
     * 数据库字段，映射成对账处理的业务字段(标准字段)
     * key：数据库中的字段，value：转换后的标准字段,这里的 value 字段也不要重复
     */
    private static Map<String, String> dataBaseFiledMapping = new HashedMap();

    static {
        dataBaseFiledMapping.put("scItemOutCode", ActivityDiffStandardFieldDict.ITEM_ID.getFieldCode());
        dataBaseFiledMapping.put("id", SalesOrderDiffStandardFieldDict.OTS_SALES_ORDER_ID.getFieldCode());
        dataBaseFiledMapping.put("outerOrderId", SalesOrderDiffStandardFieldDict.SAP_SALES_ORDER_ID.getFieldCode());
        dataBaseFiledMapping.put("orderType", SalesOrderDiffStandardFieldDict.ORDER_TYPE.getFieldCode());
        //需要转码
        dataBaseFiledMapping.put("organizationCode", SalesOrderDiffStandardFieldDict.SALE_ORGANIZATION_CODE.getFieldCode());
        dataBaseFiledMapping.put("channelCode", SalesOrderDiffStandardFieldDict.CHANNEL_CODE.getFieldCode());
        dataBaseFiledMapping.put("productGroupCode", SalesOrderDiffStandardFieldDict.PRODUCT_GROUP_CODE.getFieldCode());
        //需要转码
        dataBaseFiledMapping.put("saleChannelCode", SalesOrderDiffStandardFieldDict.SALE_CHANNEL_CODE.getFieldCode());
        dataBaseFiledMapping.put("departmentCode", SalesOrderDiffStandardFieldDict.SALE_DEPARTMENT_CODE.getFieldCode());

        dataBaseFiledMapping.put("customerCode", SalesOrderDiffStandardFieldDict.CUSTOMER_CODE.getFieldCode());
        dataBaseFiledMapping.put("receiveAddressCode", SalesOrderDiffStandardFieldDict.RECEIVE_ADDRESS_CODE.getFieldCode());
        dataBaseFiledMapping.put("cashCustomerName", SalesOrderDiffStandardFieldDict.CASH_CUSTOMER_NAME.getFieldCode());
        dataBaseFiledMapping.put("createReason", SalesOrderDiffStandardFieldDict.CREATE_REASON.getFieldCode());
        dataBaseFiledMapping.put("transportModeCode", SalesOrderDiffStandardFieldDict.TRANSPORT_MODE_CODE.getFieldCode());

        //需要转换
        dataBaseFiledMapping.put("wareHouseCode", SalesOrderDiffStandardFieldDict.WARE_HOUSE_CODE.getFieldCode());
        dataBaseFiledMapping.put("wareHouseName", SalesOrderDiffStandardFieldDict.WARE_HOUSE_NAME.getFieldCode());

        dataBaseFiledMapping.put("costCenter", SalesOrderDiffStandardFieldDict.COST_CENTER.getFieldCode());
        dataBaseFiledMapping.put("status", SalesOrderDiffStandardFieldDict.SAP_006_SUCCESS.getFieldCode());

        ;

    }

    @Override
    public Map<String, FieldLineDTO> parse(Object obj) {
        Map<String, FieldLineDTO> map = new HashMap<>();
        if (obj instanceof SalesOrderDTO) {
            SalesOrderDTO salesOrderDTO = (SalesOrderDTO) obj;
            return obtainFieldLineMap(dataBaseFiledMapping, salesOrderDTO, salesOrderDTO.getClass());
        }
        return map;
    }

    @Override
    public String obtainProcessType() {
        return "SalesOrderDTO";
    }
}
